package com.joinway.framework.core.groovy.sql

import groovy.grape.Grape
import groovy.sql.Sql

//@GrabResolver(name='maven', root='http://apps.ap.fid-intl.com/nexus/content/groups/public/')
//@GrabConfig(systemClassLoader = true)
//@Grab(group='mysql', module='mysql-connector-java', version='5.1.34')
class SqlTest {

	static main(args) {
//		ClassLoader classLoader = new GroovyClassLoader()
//		Map[] grapez = [[group : 'mysql', module : 'mysql-connector-java', version : '5.1.34']]
//		Grape.grab(classLoader: classLoader, grapez)
//		classLoader.loadClass('com.mysql.jdbc.Driver')
		
		test1()
	}

	static void test1(){
//		Class.forName('com.mysql.jdbc.Driver').newInstance()
		String ip, db
		ip = "localhost"
		db = "jiayida"
//		ip = "106.186.31.59"
//		db = "jiayidaapp"
		Sql sql = Sql.newInstance("jdbc:mysql://${ip}:3306/${db}?autoReconnect=true&useUnicode=true&characterEncoding=utf-8", 'jiayida', 'group123', 'com.mysql.jdbc.Driver')
		def c = {
			println it.getClass()
//			Map row = it
			println row
		}
		
		sql.eachRow('select * from TREE_MENU', c)
//		Map m = sql.firstRow('select * from TREE_MENU')
//		println m
//		DomainBean bean = new DomainBean(m)
//		println bean
//		
		Map m = sql.firstRow('select tm.parent_id as parentId from TREE_MENU tm')
		println m
//		
//		DomainBean2 bean2 = new DomainBean2(m)
//		println bean2
	}
}
